<?php
session_start();
if ( !isset($_SESSION['auth']) )
{
	header("Location: login.php");
	exit();
}
?>
<html>
    <head>
    <title>Liberty Unleashed Rcon</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link type="text/css" rel="stylesheet" href="css/style.css" />
	<script src="http://code.jquery.com/jquery-latest.js"></script>
	<script src="js/fancybox/jquery.fancybox-1.3.4.js"></script>
	<script src="js/jquery.contextMenu.js" type="text/javascript"></script> 
	<link rel="stylesheet" href="js/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
	<script>
		function updateChat(){
			$.ajax({
				type: "GET", url: "returnChat.php",
				complete: function(data){
					if ( data.responseText != "0" )
					{
						$("#chatbox").append(data.responseText);
						$("#chatbox").prop({ scrollTop: $("#chatbox").prop("scrollHeight") - $('#chatbox').height() });
					}
				}
			});
			setTimeout("updateChat()",2000);
		}
		updateChat();
		
		function updatePlayers(){
			$.ajax({
				type: "GET", url: "returnPlayers.php",
				complete: function(data){
					if ( data.responseText != "OFF" )
					{
						$("#playerlist").html(data.responseText);
						$("a.PlayerInfo").fancybox({ 'type': 'ajax', 'width': 500 });
						$("tr.player").contextMenu('context-menu-1', {
							'Kick Player': {
								click: function(element){
									var iID = $(element).find("td:first").html();
									var szReason = prompt("Please enter a reason for the kick:", "");
									$.get('DoAction.php?action=kick&plr=' + iID + 'reason=' + escape( szReason ), function(data) {
										alert("Player kicked!");
									});
								}
							},
							'Ban Player': {
								click: function(element){
									var iID = $(element).find("td:first").html();
									var szReason = prompt("Please enter a reason for the Ban:", "");
									$.get('DoAction.php?action=ban&plr=' + iID + 'reason=' + escape( szReason ), function(data) {
										alert("Player banned!");
									});
								}
							}
						  }
						);
					}
					else
						window.location = "login.php?down=true";
				}
			});
			setTimeout("updatePlayers()",2000);
		}
		updatePlayers();
		function Chat(){
			if ( $("#chat").val() != '' ){
				$("#loadingchat").show();
				$.ajax({
					type: "POST", url: "say.php",
					data: "msg=" + $("#chat").val(),
					complete: function(data){
						$("#chat").val('');
						$("#loadingchat").hide();
					}
				});
			}
			return false;
		}
		function UnBanIP(){
			var IP = prompt( "Please enter the IP:", "" );
			$.get('DoAction.php?action=unban&ip=' + escape( IP ), function(data) {
				alert("IP Unbanned!");
			});
		}
	</script>

	</script>
</head>
<body>
	<div id="container">
		<div id="adminbar-outer" class="radius-bottom">
			<div id="adminbar" class="radius-bottom">
				<a href="index.php" id="logo"></a>
			</div>
		</div>
		<div id="panel-outer" class="radius">
			<div id="panel" class="radius">
				<div id="content" class="clearfix">
                       <div id="side-content-right">
							<h3>Players</h3>
							<div class="body-con" id="playerlist">
							</div>
							<h3>Actions</h3>
							<div class="body-con">
								<button class="green tcenter" onclick="UnBanIP();">Unban IP</button>
								<button class="red tcenter" onclick="window.location = 'logout.php';">Logout</button>
							</div>
						</div>
						<div id="main-content-left">
							<h2>Messages</h2>
							<div class="body-con" id="chatbox" style="height: 300px; overflow: auto; border: 1px solid #CCCCCC;">
								<<<small><?php echo date("H:i:s"); ?></small>>> <?php echo $_SESSION['username']; ?> Connected trough LU-Rcon.<br/>
								<<<small><?php echo date("H:i:s"); ?></small>>> <strong>Always remember to logout when you want to leave. Or the script wont notice you're gone!</strong>
							</div>
							<form action="" onsubmit="return Chat();"><input type="text" id="chat" name="chat" class="box-xlarge"/>  <input type="submit" class="blue" value="Say" />  <img src="img/loader2.gif" id="loadingchat" style="display: none;"></form>
						</div>
				</div>
				<div id="footer" class="radius-bottom">&copy; Thijn 2011 - All rights reserved.</div>
			</div>
		</div>
	</div>
	<div class="push"></div>
</body>
</html>